﻿package 
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.utils.setTimeout;
	import makeeasier.utils.QueueSystem;
	
	/**
	$(CBI)* ...
	$(CBI)* @author Akinon
	$(CBI)*/
	public class Main extends Sprite 
	{
		
		public function Main():void 
		{
			if (stage) init();
			else addEventListener(Event.ADDED_TO_STAGE, init);
		}
		
		private function init(e:Event = null):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, init);
			// entry point
			
			var que:QueueSystem = new QueueSystem();
			que.addEventListener(Event.COMPLETE, function():void { trace("DONE!"); } );
			que.interval = 500;
			que.jobsPerInterval = 3;
			for (var i:int = 0; i < 24; i++) 
			{
				que.addJob(newBalls);
			}
			que.start();
			
			setTimeout(function():void{for (var i:int = 0; i < 24; i++) 
			{
				que.addJob(newBalls);
			}}, 7000);
		}
		
		private function newBalls():void
		{
			var spr:Sprite = new Sprite();
			spr.graphics.beginFill(0x000000, 0.1);
			spr.graphics.drawCircle(0, 0, 10);
			spr.graphics.endFill();
			spr.x = Math.random() * 600;
			spr.y = Math.random() * 400;
			addChild(spr);
		}
		
	}
	
}